#include <algorithm>
#include <iostream>
using namespace std;

const int kMaxN = 2e5 + 10;

int s[kMaxN], t[kMaxN];

int GetMin(int x, int k) {
  x %= k;
  if (x * 2 > k) {
    return k - x;
  } else {
    return x;
  }
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int T;

  for (cin >> T; T; T--) {
    int n, k;

    cin >> n >> k;
    for (int i = 0; i < n; i++) {
      cin >> s[i];
      s[i] = GetMin(s[i], k);
    }
    for (int i = 0; i < n; i++) {
      cin >> t[i];
      t[i] = GetMin(t[i], k);
    }
    sort(s, s + n);
    sort(t, t + n);

    bool equal = true;
    for (int i = 0; i < n; i++) {
      if (s[i] != t[i]) {
        equal = false;
        break;
      }
    }
    cout << (equal ? "YES\n" : "NO\n");
  }
  return 0;
}